#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct
{
    char *ch;
    int length;
}HString;

void StrAssign (HString *S,char *tval);
void StrConcat(HString *S, HString T);
int main()
{
	HString s, t;
	char a[100],b[100];

	printf("请输入字符串：");
	gets(a);
	s.length = strlen(a);
	s.ch = (char *)malloc(s.length);
	StrAssign(&s, a);

	printf("请输入需要合并的字符串：");
	gets(b);
	t.length = strlen(b);
	t.ch = (char *)malloc(t.length);
	StrAssign(&t, b);

	StrConcat(&s, t);
	printf("合并后的字符串：");
	puts(s.ch);
}
void StrAssign (HString *S,char *tval)
{
	int i;
	for(i=0;i<=S->length;i++)
		S->ch[i]=tval[i];
}

void StrConcat(HString *S, HString T)
{
	char *temp;
	int i,j;
	temp=(char *)malloc(S->length);
	if(temp==NULL)
		return;
	for(i=0;i<S->length;i++)
		temp[i]=S->ch[i];
	free(S->ch);
	S->ch=(char*)malloc(S->length+T.length);
	for(i=0;i<S->length;i++)
		S->ch[i]=temp[i];
	for(j=0;j<=T.length;j++)
		S->ch[i+j]=T.ch[j];
	S->length=S->length+T.length;
}
